package com.meihuak.cloud_ordering.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.AbstractChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meihuak.cloud_ordering.bean.Business;
import com.meihuak.cloud_ordering.bean.Canteen;
import com.meihuak.cloud_ordering.mapper.CanteenMapper;
import com.meihuak.cloud_ordering.service.BusinessService;
import com.meihuak.cloud_ordering.service.CanteenService;
import com.meihuak.cloud_ordering.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CanteenServiceImpl extends ServiceImpl<CanteenMapper, Canteen> implements CanteenService {

    @Autowired
    BusinessService businessService;
    @Autowired
    OrderService orderService;

    /**
     * 获取所有餐厅
     *
     * @return 餐厅列表
     */
    @Override
    public List<Canteen> getAllCanteen() {
        return this.list();
    }

    /**
     * 通过id修改餐厅属性
     *
     * @param canteen 餐厅id
     * @return 成功与否
     */
    @Override
    public boolean updateById(Canteen canteen) {
        return this.update(canteen, new UpdateWrapper<>());
    }

    /**
     * 添加餐厅
     *
     * @param canteen 餐厅
     * @return 成功与否
     */
    @Override
    public boolean addCanteen(Canteen canteen) {
        return this.save(canteen);
    }

    /**
     * 删除餐厅
     *
     * @param id 餐厅id
     * @return 成功与否
     */
    @Override
    public boolean removeCanteenById(int id) {
        return this.removeById(id);
    }

    /**
     * 获得餐厅的每个窗口的订单数
     *
     * @param id
     */
    @Override
    public List<Integer> getAllWinOrderNumByBid(int id) {
        List<Business> list = businessService.listByCanteenId(id);
        List<Integer> res = new ArrayList<>();
        for (Business business:list) {
            int i = orderService.getWinNoFinishOrderNumBybid(business.getId());
            res.add(i);
        }
        return res;
    }


}
